﻿//using Microsoft.Xrm.Sdk;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace isky.Plugin
//{
//   public class YGCBPlugin : Plugin
//    {
//        private readonly string _unsecureString;
//        private readonly string _secureString;
//        public YGCBPlugin(string unsecureString, string secureString)
//   : base(typeof(YGCBPlugin))
//        {
//            this._secureString = secureString;
//            this._unsecureString = unsecureString;
//            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Create", "new_ygcb", new Action<LocalPluginContext>(YgcbPreCreate)));
//            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "new_ygcb", new Action<LocalPluginContext>(YgcbPreUpdate)));
//        }

//        private void YgcbPreCreate(LocalPluginContext localContext)
//        {
//            try
//            {
//                if (localContext == null)
//                    throw new InvalidPluginExecutionException("localContext");
//                IPluginExecutionContext context = localContext.PluginExecutionContext;
//                IOrganizationService service = localContext.OrganizationService;
//                var tracingService = localContext.TracingService;
//                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
//                {
//                    Entity inputEntity = context.InputParameters["Target"] as Entity;
//                    EntityReference ygcbId = inputEntity.GetAttributeValue<EntityReference>("new_ygcbId");
//                    if (ygcbId != null)
//                    {
//                        //预计利润
//                        string yjlr = inputEntity.GetAttributeValue<string>("new_yjlr");
//                        if (yjlr == null) return;
//                        //预计重量
//                        string zhongliang = inputEntity.GetAttributeValue<string>("new_zhongliang");
//                        inputEntity.Attributes["new_profites"] = Convert.ToInt32(yjlr) * Convert.ToInt32(zhongliang);
//                    }
//                }
//            }
//            catch (Exception ex)
//            {
//                throw new InvalidPluginExecutionException(ex.Message);
//                throw new NotImplementedException();
//            }
//        }

//        private void YgcbPreUpdate(LocalPluginContext localContext)
//        {
//            try
//            {
//                if (localContext == null)
//                    throw new InvalidPluginExecutionException("localContext");
//                IPluginExecutionContext context = localContext.PluginExecutionContext;
//                IOrganizationService service = localContext.OrganizationService;
//                var tracingService = localContext.TracingService;
//                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
//                {
//                    Entity inputEntity = context.InputParameters["Target"] as Entity;
//                    EntityReference ygcbId = inputEntity.GetAttributeValue<EntityReference>("new_ygcbId");
//                    if (ygcbId != null)
//                    {
//                        //预计利润
//                        string yjlr = inputEntity.GetAttributeValue<string>("new_yjlr");
//                        if (yjlr == null) return;
//                        //预计重量
//                        string zhongliang = inputEntity.GetAttributeValue<string>("new_zhongliang");
//                        inputEntity.Attributes["ws_orderdetail"] = Convert.ToInt32(yjlr) * Convert.ToInt32(zhongliang);
//                    }
//                }
//            }
//            catch (Exception ex)
//            {
//                throw new InvalidPluginExecutionException(ex.Message);
//                throw new NotImplementedException();
//            }
//        }
//    }
//}
